package com.powernode.simplefactory;

/**
 * 工厂类角色
 */
public class WeaponFactory {
    /**
     * 根据不同的武器类型生产武器
     * @param weaponType 武器类型
     * @return 武器对象
     */
    public static Weapon get(String weaponType){
        if (weaponType == null || weaponType.trim().length() == 0) {
            return null;
        }
        Weapon weapon = switch (weaponType) {
            case "TANK" -> new Tank();
            case "FIGHTER" -> new Fighter();
            case "DAGGER" -> new Dagger();
            default -> throw new RuntimeException("不支持该武器！");
        };
        return weapon;
    }

}
